﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Data;
using Model;
using NHibernate.Cfg;
using NHibernate.Mapping;
using NHibernate.Tool.hbm2ddl;

namespace NHibernateDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            button1.Click += Button1OnClick;
            button2.Click += Button2OnClick;
            button3.Click += Button3OnClick;
        }

        private void Button3OnClick(object sender, EventArgs eventArgs)
        {
            NHibernate.Cfg.Configuration configuration = new NHibernate.Cfg.Configuration().Configure();
            NHibernate.Tool.hbm2ddl.SchemaExport schemaExport = new SchemaExport(configuration);
            schemaExport.Create(true,false);
            
            schemaExport.SetOutputFile(@"D:\schma.sql");

        }

        private void Button2OnClick(object sender, EventArgs eventArgs)
        {
            User u1 = new User()
            {
                UserName = "张三",
                Salt = "ABCDEF",
                Email = "mzy_666888@126.com",
                Password = "123456"
            };
            BaseDal<User> dal = new BaseDal<User>();
            dal.Insert(u1);
            User user = dal.Query(1);
            List<User> list = new List<User>();
            list.Add(user);
            dataGridView2.DataSource = list;
        }

        private void Button1OnClick(object sender, EventArgs eventArgs)
        {
            Data.ICustomerRespository customer = new CustomerRespository();

            IList<Customer> list = customer.Query();
            dataGridView1.DataSource = list;
        }
    }
}
